package com.xyoto.community.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xyoto.community.dto.PageDTO;
import com.xyoto.community.entity.main.CampusNewsFlash;
import com.xyoto.community.mapper.main.CampusNewsFlashMapper;
import com.xyoto.community.service.CampusNewsFlashService;
import com.xyoto.community.utils.PageUtils;
import com.xyoto.community.utils.Result;
import com.xyoto.community.vo.CampusNewsFlashVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * Author: 廖振辉
 * Date: 2021/11/17
 * Description: 校园快讯service实现类
 */
@Service
public class CampusNewsFlashServiceImpl implements CampusNewsFlashService {

    @Autowired
    private CampusNewsFlashMapper campusNewsFlashMapper;

    /**
     * 获取当前处于正在展示状态的校园快讯
     * @author 廖振辉
     * @return {@link Result}
     */
    @Override
    public Result getAll() {
        List<CampusNewsFlash> campusNewsFlashList = campusNewsFlashMapper.selectListByOrders();
        ArrayList<CampusNewsFlashVO> campusNewsFlashVOS = new ArrayList<>(campusNewsFlashList.size());
        for (CampusNewsFlash campusNewsFlash : campusNewsFlashList) {
            campusNewsFlashVOS.add(new CampusNewsFlashVO(campusNewsFlash.getId(),campusNewsFlash.getTitle(),campusNewsFlash.getLink()));
        }
        return Result.success(campusNewsFlashVOS);
    }
}
